package com.company.ems.util;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class VerifyAssignmentDatabase {
    
    public static void main(String[] args) {
        System.out.println("验证作业数据库数据...");
        
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        
        try {
            conn = DatabaseUtil.getConnection();
            
            // 查询用户数据
            String queryUsers = "SELECT * FROM users";
            pstmt = conn.prepareStatement(queryUsers);
            rs = pstmt.executeQuery();
            
            System.out.println("\n=== 用户数据 ===");
            while (rs.next()) {
                System.out.println("ID: " + rs.getInt("id") + 
                    ", 用户名: " + rs.getString("username") + 
                    ", 邮箱: " + rs.getString("email") +
                    ", 创建时间: " + rs.getTimestamp("created_at"));
            }
            
            // 查询员工数据
            String queryEmployees = "SELECT * FROM employees";
            pstmt = conn.prepareStatement(queryEmployees);
            rs = pstmt.executeQuery();
            
            System.out.println("\n=== 员工数据 ===");
            while (rs.next()) {
                System.out.println("ID: " + rs.getInt("id") + 
                    ", 姓名: " + rs.getString("name") + 
                    ", 部门: " + rs.getString("department") +
                    ", 职位: " + rs.getString("position") +
                    ", 薪资: " + rs.getBigDecimal("salary") +
                    ", 邮箱: " + rs.getString("email") +
                    ", 电话: " + rs.getString("phone") +
                    ", 入职日期: " + rs.getDate("hire_date") +
                    ", 创建者ID: " + rs.getInt("created_by"));
            }
            
            System.out.println("\n数据库验证完成！");
            
        } catch (SQLException e) {
            System.err.println("✗ 数据库验证失败: " + e.getMessage());
            e.printStackTrace();
        } finally {
            DatabaseUtil.closeConnection(conn, pstmt, rs);
        }
    }
}